package StudyCode.summary.Basic.autocloseable;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class AutoCloseableResource {
	public static void main(String[] args) {
		// close() 方法将被自动调用
		try (MyResource mr = new MyResource()) {
			mr.use();
			mr.use();
		}
	}
}


class MyResource implements AutoCloseable {

	public void use() {
		System.out.println("use 方法被调用");
	}

	@Override
	public void close() {
		System.out.println("close 方法被调用");
	}
}
